<template>
  <div class="app-container">
    <el-divider content-position="left"><legend class="divider-line">敏感词过滤设置</legend></el-divider>
    <section class="text-annotation">
      启用敏感词过滤之后，输入敏感词将搜索不到任何结果。
    </section>
    <el-form :inline="true" :model="listQuery" :rules="rules" @submit.native.prevent>
      <el-form-item label="敏感词过滤" prop="keywordFilter">
        <el-radio v-model="listQuery.keywordFilter" v-for="item in statesList" :key="item.value" :label="item.value">{{ item.name }}</el-radio>
      </el-form-item>
    </el-form>
    <el-button @click="submitIndexes" type="primary" size="medium" v-permission="['admin/search/updateKeywordfilter']">立即提交</el-button>
  </div>
</template>
<script>
import { keywordfilterListSearch, keywordfilterSearch } from '@/api/search';
import { getCodeManager, codeToArray } from "@/api/all"
export default {
  name: 'keywordfilterList',
  data() {
    return {
      fullscreenLoading: false,
      statesList: [],
      listQuery: {
        keywordFilter: ''
      },
      rules: {
        keywordFilter: [
          { required: true, message: "是否过滤敏感词必选", trigger: "change" }
        ]
      }
    }
  },
  created() {
    getCodeManager("SEARCH_KEYWORDFILTER", () => {
      this.statesList = codeToArray("SEARCH_KEYWORDFILTER");
    });
    keywordfilterListSearch().then(res=> this.listQuery.keywordFilter = ''+res.data.data.searchSetting.keywordFilter)
  },
  methods: {
    submitIndexes() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      this.$confirm("确定提交吗？", "提示", {
        onfirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        keywordfilterSearch(this.listQuery).then(res => {
          if(res.data.success) {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            loading.close();
          } else {
            this.$message({
              type: "error",
              message: res.data.message
            });
            loading.close();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交'
        });
        loading.close();
      });
    }
  }
}
</script>
<style scope>
.text-annotation {
  border-style: solid;
  border-width: 1px 1px 1px 5px;
  background: 0 0;
  border-color: #e6e6e6;
  margin-bottom: 30px;
  padding: 15px;
  line-height: 22px;
  border-radius: 0 2px 2px 0;
  color: #666;
  font-size: 14px;
}
</style>
